import { Strategy, StrategyOptions, ExtractJwt } from "passport-jwt"
import { PassportStrategy } from '@nestjs/passport';
import { InjectModel } from "nestjs-typegoose";
import { ModelType } from "@typegoose/typegoose/lib/types";
import { WebUserModel } from "src/mongodb/models/userModel/webUser.models";


/* token策略 */
export class jwtwebStrategy extends PassportStrategy(Strategy, "jwtweb") {

    constructor(@InjectModel(WebUserModel) private readonly user: ModelType<WebUserModel>) {
        super({
            jwtFromRequest: ExtractJwt.fromHeader('token'),
            ignoreExpiration: false,
            secretOrKey: '4N6UCQTNI0JFZ2UFYDDLLC4KNABC6L5VRH0K83A8UT'
        } as StrategyOptions)
    }


    async validate({ data }) {
        return await this.user.findById(data)
    }

}




